<template>
  <div class="hello">
    <h1>使用vuex管理数据</h1>
    <h2>{{count}}</h2>
    <h3>{{doubleCount}}</h3>
    <button @click='incCount()'>改变数据</button>
    <h2>获取元素上 data- 设置的属性数据</h2>
    <div data-id="999" @click="myClick($event)">获取自定义数据</div>
  </div>
</template>

<script>
import {mapState, mapMutations, mapGetters} from 'vuex'
import store from '@/store'
export default {
  store,
  name: 'HelloWorld',
  data () {
    return {
    }
  },
  computed: {
    ...mapState({
      // eslint-disable-next-line no-undef
      count: 'count'
    }),
    ...mapGetters({
      doubleCount: 'doubleCount'
    })
  },
  methods: {
    ...mapMutations({
      incCount: 'incCount'
    }),
    myClick (e) {
      alert(e.srcElement.dataset.id)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
